﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestPrj
{
    public class StringProcess
    {
        public void Execute()
        {
            // 读取整个文件内容
         //   string content = File.ReadAllText("E:/1.txt");

            // 按行读取到字符串数组
            string[] lines01 = File.ReadAllLines("E:/1.txt");
            string[] lines02 = File.ReadAllLines("E:/2.txt");

            Dictionary<string,string> dic01 = new Dictionary<string,string>();
            Dictionary<string,string> dic02 = new Dictionary<string,string>();
            foreach (string line in lines01)
            {
                string[] columns = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (columns.Length > 0)
                {
                    dic01[columns[0]] = columns[1];
                }

            }

            foreach (string line in lines02)
            {
                string[] columns = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (columns.Length > 0)
                {
                    dic02[columns[0]] = columns[1];
                }

            }

            StreamWriter writersame = new StreamWriter("E:/outsame.txt");
            StreamWriter writerdiff = new StreamWriter("E:/outdiff.txt");
          
            foreach (var item in dic01)
            {
                if (dic02[item.Key] == item.Value)
                {
                    writersame.WriteLine($"{item.Key}\t{dic01[item.Key]}\t{dic02[item.Key]}");
                }
                else
                {
                    writersame.WriteLine($"{item.Key}\t{dic01[item.Key]}\t{dic02[item.Key]}");
                }

            }
            writersame.Close();
            writerdiff.Close(); 

        }
    }
}
